package com.heima.article.MQ;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.model.article.ApArticleConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
public class Mqjs {
    @Autowired
    private ApArticleConfigMapper apArticleConfigMapper;

    //文章下架处理sssss
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "wm.queue", durable = "true"),
            exchange = @Exchange(name = "wm.direct"),
            key = "wm"
    ))
    public void wm(HashMap map) {
        log.info("MQ消息已到达");
        System.err.println(map.get("articleId"));
        System.err.println(map.get("enable"));
        LambdaQueryWrapper<ApArticleConfig> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ApArticleConfig::getArticleId, map.get("articleId"));
        ApArticleConfig apArticleConfig = apArticleConfigMapper.selectOne(wrapper);
        boolean falg = false;
        if (map.get("enable").equals(0)) {
            falg = true;
        }
        apArticleConfig.setIsDown(falg);
        apArticleConfigMapper.updateById(apArticleConfig);
    }
}
